package com.mqz.seckill.rabbitmq;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
@Slf4j
public class MQProducer {
    @Resource
    private RabbitTemplate rabbitTemplate;

    public void send(Object msg) {
        log.info("发送消息：" + msg);
        rabbitTemplate.convertAndSend("queue", msg);
    }

    public void sendToFanout(Object msg) {
        log.info("发送消息: " + msg);
        rabbitTemplate.convertAndSend("fanout_exchange", "", msg);
    }

    public void sendToDirect01(Object msg) {
        log.info("发送消息: " + msg);
        rabbitTemplate.convertAndSend("direct_exchange", "channel01", msg);
    }

    public void sendToDirect02(Object msg) {
        log.info("发送消息: " + msg);
        rabbitTemplate.convertAndSend("direct_exchange", "channel02", msg);
    }

    public void sendToTopic01(Object msg) {
        log.info("发送消息: " + msg);
        rabbitTemplate.convertAndSend("topic_exchange", "queue.red.yellow", msg);
    }

    public void sendToTopic02(Object msg) {
        log.info("发送消息: " + msg);
        rabbitTemplate.convertAndSend("topic_exchange", "a.queue.bb", msg);
    }

}
